/*
 * Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
 *
 * Licensed under the Mulan PSL v2.
 * You can use this file according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of the License at
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
 * FOR MORE DETAILS.
 */

#pragma once

#include <set>
#include <vector>

#include "DataStructure/Common/Id.h"
#include "DataStructure/Common/Out.h"
#include "DataStructure/Common/Status.h"

#include "DBManager/IRepository/Base/IRepository.h"

SG_DBMANAGER_HDF5_NAMESPACE_OPEN

/**
 * @brief   : nastran 的结果数据索引
 */
struct ResultDomainIndex
{
    SG::DataStructure::Common::I64 DOMAIN_ID;
    SG::DataStructure::Common::I64 POSITION;
    SG::DataStructure::Common::I64 LENGTH;

    ResultDomainIndex () : DOMAIN_ID (0), POSITION (0), LENGTH (0)
    {}

    ResultDomainIndex (SG::DataStructure::Common::I64 _domainId,
                       SG::DataStructure::Common::I64 _position,
                       SG::DataStructure::Common::I64 _length)
        : DOMAIN_ID (_domainId), POSITION (_position), LENGTH (_length)
    {}

    bool operator< (const ResultDomainIndex& other) const
    {
        return DOMAIN_ID < other.DOMAIN_ID;
    }
};

SG_DBMANAGER_HDF5_NAMESPACE_CLOSE

template <class T>
class IResultRepository : IRepository
{
  public:
    /**
     * @brief 获取指domain的实体总数。
     */
    virtual std::size_t Size (SG::DataStructure::Common::Id domainId) = 0;

    /**
     * @brief 使用向量添加数据，tip: 针对相同的 ID 只能添加一次。
     */
    virtual SG::DataStructure::Common::Status Add (SG::DataStructure::Common::Id domainId, std::vector<T>& entities) = 0;

    /**
     * @brief   : 获取 对应domain的数据
     * @param   : domainId
     * @param   : entity
     * @return  :
     */
    virtual SG::DataStructure::Common::Status FindByDomainId (SG::DataStructure::Common::Id domainId, std::vector<T>& _OUT entities) = 0;

    /**
     * @brief   : 获取 对应domain的数据，可使用eIdSet进一步对子集的主键进行筛选
     * @param   : domainId
     * @param   : entity
     * @param   : eIdSet
     * @return  :
     */
    virtual SG::DataStructure::Common::Status FindByDomainId (SG::DataStructure::Common::Id           domainId,
                                                              std::set<SG::DataStructure::Common::Id> eIdSet,
                                                              std::vector<T>& _OUT                    entities) = 0;
};